class LabelLinksController < ApplicationController
  #If AJAX request, use the slim layout (no header or footer)
  #Otherwise use the main layout
  layout Proc.new { |controller| controller.request.xhr? ? 'slim' : 'main' }

  def new
    @edition = Edition.find(params[:edition_id])
  end
  
  def search
  	@labels = Label.search(params[:search])
	
	respond_to do |format|
	  format.html { }
	  format.js {
	    render :update do |page|
		  page.replace_html("label-search-results", :partial => 'results',
		                                            :locals => { :labels => @labels })
		end
	  }
	end
  end
  
  def create
    @edition = Edition.find(params[:edition_id])
	
	if params[:label_id]
	  @edition.label = Label.find(params[:label_id])
	else
	  new_label = Label.new(:name => params[:label_name])
	  @edition.label = new_label
	end
	
	respond_to do |format|
	  if @edition.save
	    flash[:notice] = 'Label successfully added.'
		format.html { redirect_to edit_release_edition_path(@edition.release, @edition) }
	  else
	    flash[:error] = @edition.errors.full_messages
		format.html { redirect_to edit_release_edition_path(@edition.release, @edition) }
	  end
	end
	
  end
  
  def destroy
  
  end

end
